﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Globalization;
using System.Xml;

namespace Nuane.Posterous
{
	/// <summary>
	/// A posterous comment.
	/// </summary>
	public class PosterousComment
	{
		//<comment>  
		//  <body>This is a comment</body>  
		//  <date>Thu, 04 Jun 2009 01:33:43 -0700</date>  
		//  <author>sachin</author>  
		//  <authorpic>http://debug2.posterous.com/user_profile_pics/16071/Picture_1_thumb.png</authorpic>  
		//</comment>

		/// <summary>
		/// Gets the body of this comment.
		/// </summary>
		/// <value>Comment body.</value>
		public string Body { get; private set; }

		/// <summary>
		/// Gets the UTC datetime of this comment.
		/// </summary>
		/// <value>Comment UTC datetime.</value>
		public DateTime Date { get; private set; }

		/// <summary>
		/// Gets the comment author.
		/// </summary>
		/// <value>Comment author.</value>
		public string Author { get; private set; }

		/// <summary>
		/// Gets the comment author picture URI, if available;
		/// </summary>
		/// <value>Comment author picture URI; or null (Nothing in VB.NET) if not available.</value>
		public Uri AuthorPictureUri { get; private set; }

		internal PosterousComment(XmlNode site)
		{
			if (site.Name != "comment")
				throw new PosterousException("Invalid response.", PosterousExceptionStatus.ServerProtocolViolation);

			Body = Helper.GetChildElementValue(site, "body");
			Date = Helper.ToDateTime(Helper.GetChildElementValue(site, "date"));
			Author = Helper.GetChildElementValue(site, "author");
			AuthorPictureUri = Helper.ToUri(Helper.GetChildElementValue(site, "authorpic", false), true);
		}
	}
}

